﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

public partial class admin_Report : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ArrayList listado_arr = new ArrayList();
        ListItem item = null;
        if (!Page.IsPostBack)
        {
            lb_agent.Items.Clear();
            listado_arr = (ArrayList)DB.getListado("tbl_usuario_descripcion, tbl_usuario_perfil", "ude_nombre+' '+ude_apellido, UDE_ID", "upe_ude_id=ude_id and upe_per_id=3 and upe_estado=1");
            if ((listado_arr != null) && (listado_arr.Count > 0))
            {
                item = new ListItem("ALL", "");
                lb_agent.Items.Add(item);
                foreach (RE_GenericBean rgb in listado_arr)
                {
                    item = new ListItem(rgb.strC1, rgb.strC1);
                    lb_agent.Items.Add(item);
                }
            }
        }

    }
    protected void bt_search_Click(object sender, EventArgs e)
    {
        string where = " dat_xml.query('//campos/frmAgentName').value('.', 'varchar(max)') <>''";
        if (!tb_startdate.Text.Equals("")) where += " and dat_xml.query('//campos/frmDateIn').value('.', 'datetime')>='" + tb_startdate.Text + "'";
        if (!tb_enddate.Text.Equals("")) where += " and dat_xml.query('//campos/frmDateIn').value('.', 'datetime')<='" + tb_enddate.Text + "'";
        if (!lb_agent.SelectedValue.Equals("")) where += " and dat_xml.query('//campos/frmAgentName').value('.', 'varchar(max)')='" + lb_agent.SelectedValue + "'";
        if (lb_typeofsale.SelectedValue.Equals("APPROVED")) where += " and dat_xml.query('//campos/frmQCStatus').value('.', 'varchar(max)')='APPROVED'"; 
        else where += "and dat_xml.query('//campos/frmQCStatus').value('.', 'varchar(max)')<>'APPROVED'";
        //if (!lb_report_type.SelectedValue.Equals("")) where += " and dat_xml.query('//campos/frmTypeSale').value('.', 'varchar(max)')='" + lb_report_type.SelectedValue + "'";
        ReportDS ds = new ReportDS();
        ds = DB.getAgentData(where);
        CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

        if (lb_report_type.SelectedValue.Equals("Agent"))
            rpt.Load(Server.MapPath("~/CR_Agent.rpt"));
        else if (lb_report_type.SelectedValue.Equals("Day"))
            rpt.Load(Server.MapPath("~/CR_Group.rpt"));
        rpt.SetDataSource(ds.Tables["tbl_agent"]);
        CrystalReportViewer1.ReportSource = rpt;
        CrystalReportViewer1.DataBind();
    }
    protected void CrystalReportViewer1_Init(object sender, EventArgs e)
    {

    }
}